home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 2
/
Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso
/
Aminet
/
comm
/
uucp
/
AM114src.lha
/
getaddress.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-20
|
12KB
|
509 lines
/*
*
* AM --- AmigaMail
* (C) 1991, 1992, 1992 by Christian Riede
*
* AM is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY. No author or distributor accepts responsibility to anyone
* for the consequences of using it or for whether it serves any
* particular purpose or works at all, unless he says so in writing.
* Refer to the GNU General Public License, Version 1, for full details.
*
* Everyone is granted permission to copy, modify and redistribute AM,
* but only under the conditions described in the GNU General Public
* License, Version 1. A copy of this license is supposed to have been
* given to you along with AM so you can know your rights and responsi-
* bilities. It should be in a file named COPYING. Among other things,
* the copyright notice and this notice must be preserved on all copies.
*
*
*
*/
#include "am.h"
#define TO 101
#define CC 102
#define BCC 103
#define SUBJECT 104
#define OK 105
#define CANCEL 106
/* reentrant */
int GetAddress(char *To,char *Cc, char *Bcc, char *Subject)
{
int run,ok;
struct IntuiMessage *Msg;
ULONG Class;
ULONG Code;
APTR IAddr;
struct Gadget *GList,*gad,*ToGad,*CcGad,*BccGad,*SubjGad,*ListGad,*ActiveGad;
struct Window *ABWindow=0;
struct List Addressbook;
int LastSelected=-1;
struct Address *Address;
char Buffer[MAIL_FIELDLENGTH];
struct NewGadget ABListGadget =
{
0,0,0,0,
0 /*(UBYTE *)"To:"*/ ,&TextAttr,
LIST,
PLACETEXT_ABOVE,
0,
0
};
struct NewGadget ToGadget =
{
0,0,0,0,
(UBYTE *)"To:",&TextAttr,
TO,
PLACETEXT_LEFT,
0,
0
};
struct NewGadget CcGadget =
{
0,0,0,0,
(UBYTE *)"Cc:",&TextAttr,
CC,
PLACETEXT_LEFT,
0,
0
};
struct NewGadget BccGadget =
{
0,0,0,0,
(UBYTE *)"Bcc:",&TextAttr,
BCC,
PLACETEXT_LEFT,
0,
0
};
struct NewGadget SubjectGadget =
{
0,0,0,0,
(UBYTE *)"Subject:",&TextAttr,
SUBJECT,
PLACETEXT_LEFT,
0,
0
};
struct NewGadget OKGadget =
{
0,0,0,0,
(UBYTE *)"Ok",&TextAttr,
OK,
PLACETEXT_IN,
0,
0
};
struct NewGadget CANCELGadget =
{
0,0,0,0,
(UBYTE *)"Cancel",&TextAttr,
CANCEL,
PLACETEXT_IN,
0,
0
};
if (Screen) /* custom screen requested */
{
if (!(ABWindow = OpenWindowTags(0,
WA_CustomScreen,Screen,
WA_Left,ABLeft,
WA_Top,ABTop,
WA_Width,ABWidth,
WA_Height,(Screen->Height<360)?(ABHeight1):(ABHeight2),
WA_MinWidth,640L,
WA_MinHeight,180L,
WA_MaxWidth,1024L,
WA_MaxHeight,1024L,
WA_DragBar,TRUE,
WA_DepthGadget,TRUE,
WA_CloseGadget,TRUE,
WA_Activate,TRUE,
WA_SmartRefresh,TRUE,
WA_GimmeZeroZero,TRUE,
WA_RMBTrap,TRUE,
TAG_END)))
{
FreeAddressBook(&Addressbook);
SimpleRequest(Window,"Can't open Addressbook-Window");
return(FALSE);
}
}
else if (PubScreen) /* public screen requested */
{
if (!(ABWindow = OpenWindowTags(0,
WA_PubScreen,(UBYTE *)PubScreen,
WA_Left,ABLeft,
WA_Top,ABTop,
WA_Width,ABWidth,
WA_Height,(PubScreen->Height<360)?(ABHeight1):(ABHeight2),
WA_MinWidth,640L,
WA_MinHeight,180L,
WA_MaxWidth,1024L,
WA_MaxHeight,1024L,
WA_DragBar,TRUE,
WA_DepthGadget,TRUE,
WA_CloseGadget,TRUE,
WA_Activate,TRUE,
WA_SmartRefresh,TRUE,
WA_GimmeZeroZero,TRUE,
WA_RMBTrap,TRUE,
TAG_END)))
{
FreeAddressBook(&Addressbook);
SimpleRequest(Window,"Can't open Addressbook-Window");
return(FALSE);
}
}
else
return(FALSE);
/* read Addressbook */
ReadAddressBook(&Addressbook);
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
GList = gad = 0;
/* get visualinfo */
if(!(ABListGadget.ng_VisualInfo = GetVisualInfo(ABWindow->WScreen,TAG_END)))
{
SimpleRequest(Window,"Can't get visual info");
FreeAddressBook(&Addressbook);
CloseWindow(ABWindow);
return(FALSE);
}
ToGadget.ng_VisualInfo = ABListGadget.ng_VisualInfo;
CcGadget.ng_VisualInfo = ABListGadget.ng_VisualInfo;
BccGadget.ng_VisualInfo = ABListGadget.ng_VisualInfo;
SubjectGadget.ng_VisualInfo = ABListGadget.ng_VisualInfo;
OKGadget.ng_VisualInfo = ABListGadget.ng_VisualInfo;
CANCELGadget.ng_VisualInfo = ABListGadget.ng_VisualInfo;
/* allocate context */
if (!(gad = CreateContext(&GList)))
{
CloseWindow(ABWindow);
FreeAddressBook(&Addressbook);
SimpleRequest(Window,"Can't create context");
return(TRUE);
}
/* adjust gadgets to window dimensions */
OKGadget.ng_LeftEdge = 5;
OKGadget.ng_TopEdge = ABWindow->GZZHeight-TextAttr.ta_YSize-8;
OKGadget.ng_Width = 100; /* !!!!!!!!!!!!!!! */
OKGadget.ng_Height = TextAttr.ta_YSize+4;
CANCELGadget.ng_LeftEdge = ABWindow->GZZWidth-OKGadget.ng_Width-5;
CANCELGadget.ng_TopEdge = OKGadget.ng_TopEdge;
CANCELGadget.ng_Width = OKGadget.ng_Width;
CANCELGadget.ng_Height = OKGadget.ng_Height;
SubjectGadget.ng_LeftEdge = 100;
SubjectGadget.ng_TopEdge = OKGadget.ng_TopEdge-TextAttr.ta_YSize-6;
SubjectGadget.ng_Width = ABWindow->GZZWidth-5-100;
SubjectGadget.ng_Height = TextAttr.ta_YSize+4;
BccGadget.ng_LeftEdge = 100;
BccGadget.ng_TopEdge = SubjectGadget.ng_TopEdge-TextAttr.ta_YSize-6;
BccGadget.ng_Width = SubjectGadget.ng_Width;
BccGadget.ng_Height = TextAttr.ta_YSize+4;
CcGadget.ng_LeftEdge = 100;
CcGadget.ng_TopEdge = BccGadget.ng_TopEdge-TextAttr.ta_YSize-6;
CcGadget.ng_Width = SubjectGadget.ng_Width;
CcGadget.ng_Height = TextAttr.ta_YSize+4;
ToGadget.ng_LeftEdge = 100;
ToGadget.ng_TopEdge = CcGadget.ng_TopEdge-TextAttr.ta_YSize-6;
ToGadget.ng_Width = SubjectGadget.ng_Width;
ToGadget.ng_Height = TextAttr.ta_YSize+4;
ABListGadget.ng_LeftEdge = 5;
ABListGadget.ng_TopEdge = 5 /*+TextAttr.ta_YSize*/;
ABListGadget.ng_Width = ABWindow->GZZWidth-10;
ABListGadget.ng_Height = ToGadget.ng_TopEdge-ABListGadget.ng_TopEdge-5;
/* create OK gadget */
if(!(gad = CreateGadget(BUTTON_KIND,gad,&OKGadget,
GA_RELVERIFY,TRUE,
TAG_END)))
{
CloseWindow(ABWindow);
FreeAddressBook(&Addressbook);
SimpleRequest(Window,"Can't create ok gadget");
return(TRUE);
}
/* create CANCEL gadget */
if(!(gad = CreateGadget(BUTTON_KIND,gad,&CANCELGadget,
GA_RELVERIFY,TRUE,
TAG_END)))
{
FreeAddressBook(&Addressbook);
SimpleRequest(Window,"Can't create cancel gadget");
return(TRUE);
}
/* get ToGadget */
if (!(ToGad = gad = CreateGadget(STRING_KIND,gad,&ToGadget,
GTST_MaxChars,MAIL_FIELDLENGTH,
GA_TabCycle,TRUE,
GA_Immediate,TRUE,
TAG_END)))
{
CloseWindow(ABWindow);
FreeAddressBook(&Addressbook);
SimpleRequest(Window,"Can't create To gadget");
return(TRUE);
}
/* get CcGadget */
if (!(CcGad = gad = CreateGadget(STRING_KIND,gad,&CcGadget,
GTST_MaxChars,MAIL_FIELDLENGTH,
GA_TabCycle,TRUE,
GA_Immediate,TRUE,
TAG_END)))
{
CloseWindow(ABWindow);
FreeAddressBook(&Addressbook);
SimpleRequest(Window,"Can't create Cc gadget");
return(TRUE);
}
/* get BccGadget */
if (!(BccGad = gad = CreateGadget(STRING_KIND,gad,&BccGadget,
GTST_MaxChars,MAIL_FIELDLENGTH,
GA_TabCycle,TRUE,
GA_Immediate,TRUE,
TAG_END)))
{
CloseWindow(ABWindow);
FreeAddressBook(&Addressbook);
SimpleRequest(Window,"Can't create Bcc gadget");
return(TRUE);
}
/* get SubjectGadget */
if (!(SubjGad = gad = CreateGadget(STRING_KIND,gad,&SubjectGadget,
GTST_MaxChars,MAIL_FIELDLENGTH,
GA_TabCycle,TRUE,
GA_Immediate,TRUE,
TAG_END)))
{
CloseWindow(ABWindow);
FreeAddressBook(&Addressbook);
SimpleRequest(Window,"Can't create To gadget");
return(TRUE);
}
/* get listview-gadget */
if (!(ListGad = gad = CreateGadget(LISTVIEW_KIND,gad,&ABListGadget,
GTLV_Labels,&Addressbook,
/* GTLV_ShowSelected,ToGad,*/
TAG_END)))
{
CloseWindow(ABWindow);
FreeAddressBook(&Addressbook);
SimpleRequest(Window,"Can't create listview gadget");
return(TRUE);
}
/* show up gadgets */
AddGList(ABWindow,GList,-1,-1,NULL);
RefreshGList(GList,ABWindow,NULL,-1);
GT_RefreshWindow(ABWindow,0);
ModifyIDCMP(ABWindow,GADGETUP|GADGETDOWN|LISTVIEWIDCMP|CLOSEWINDOW);
ActivateGadget(ToGad,ABWindow,0);
ActiveGad = ToGad;
/* main loop */
run = TRUE;
ok = FALSE;
while (run)
{
Wait(1L<<ABWindow->UserPort->mp_SigBit);
while (Msg = GT_GetIMsg(ABWindow->UserPort))
{
/* remember values */
Class = Msg->Class;
Code = Msg->Code;
IAddr = Msg->IAddress;
/* reply message */
GT_ReplyIMsg(Msg);
/* dispatch */
switch(Class)
{
case CLOSEWINDOW:
strcpy(To,"");
run = FALSE;
ok = FALSE;
break;
case REFRESHWINDOW:
GT_BeginRefresh(ABWindow);
GT_EndRefresh(ABWindow,TRUE);
break;
case GADGETUP:
switch(((struct Gadget *)IAddr)->GadgetID)
{
case LIST: /* user selected item */
LastSelected = Code;
if (Address = (struct Address *)
findnode(&Addressbook,Code));
{
if (strlen((char *)((struct StringInfo *)
ActiveGad->SpecialInfo)->Buffer)>MAIL_FIELDLENGTH)
DisplayBeep(0L);
else
{
if (ActiveGad)
{
sprintf(Buffer,"\"%s\" <%s>",
/*(char *)((struct StringInfo *)
ActiveGad->SpecialInfo)->Buffer,*/
Address->Realname,
Address->Username);
GT_SetGadgetAttrs(ActiveGad,ABWindow,0,
GTST_String,(ULONG)Buffer,
TAG_END,0);
ActivateGadget(ActiveGad,ABWindow,0);
}
}
}
break;
case CANCEL:
strcpy(To,"");
strcpy(Cc,"");
strcpy(Bcc,"");
strcpy(Subject,"");
run = FALSE;
ok = FALSE;
break;
case SUBJECT:
if (Code==0x09) /* GA_TabCycle */
{
ActiveGad = ToGad;
break;
} /* else go on with OK */
case OK:
strcpy(To,(char *)((struct StringInfo *)ToGad->SpecialInfo)->Buffer);
strcpy(Cc,(char *)((struct StringInfo *)CcGad->SpecialInfo)->Buffer);
strcpy(Bcc,(char *)((struct StringInfo *)BccGad->SpecialInfo)->Buffer);
strcpy(Subject,(char *)((struct StringInfo *)SubjGad->SpecialInfo)->Buffer);
if (!*To)
{
SimpleRequest(ABWindow,"No To: address selected!");
ActivateGadget(ToGad,ABWindow,0);
}
else if (!*Subject)
{
SimpleRequest(ABWindow,"Please Enter a Subject");
ActivateGadget(SubjGad,ABWindow,0);
}
else
{
run = FALSE;
ok = TRUE;
}
break;
case TO:
ActivateGadget(CcGad,ABWindow,0);
ActiveGad = CcGad;
break;
case CC:
ActivateGadget(BccGad,ABWindow,0);
ActiveGad = BccGad;
break;
case BCC:
ActivateGadget(SubjGad,ABWindow,0);
ActiveGad = SubjGad;
break;
default:
puts("unknown gadget");
}
case GADGETDOWN:
switch(((struct Gadget *)IAddr)->GadgetID)
{
case TO:
case CC:
case BCC:
case SUBJECT:
ActiveGad = (struct Gadget *)IAddr;
break;
case LIST:
break;
default:
ActiveGad = 0;
break;
}
break;
case MOUSEBUTTONS:
break;
case INTUITICKS:
break;
default:
printf("Unknkown IntuiMessage->Class:%x\n",Class);
break;
}
}
}
/* get to, subject */
strcpy(To,(char *)((struct StringInfo *)ToGad->SpecialInfo)->Buffer);
strcpy(Subject,(char *)((struct StringInfo *)SubjGad->SpecialInfo)->Buffer);
/* remove,free gadgets */
RemoveGList(ABWindow,GList,-1);
FreeGadgets(GList);
if (!ok)
{
FreeVisualInfo(ABListGadget.ng_VisualInfo);
CloseWindow(ABWindow);
return(FALSE);
}
FreeVisualInfo(ABListGadget.ng_VisualInfo);
CloseWindow(ABWindow);
/* free assressbook */
FreeAddressBook(&Addressbook);
return(TRUE);
}